package com.example.work2;

import static android.content.Context.ACTIVITY_SERVICE;

import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class BootCompleteReceiver extends BroadcastReceiver {
    public static int MEMORY;
    int time = 0;
    @Override
    public void onReceive(Context context, Intent intent){

        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    if (time<=1000*600) {
                        time = doWork();
                        ActivityManager am = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
                        ActivityManager.MemoryInfo outInfo = new ActivityManager.MemoryInfo();
                        am.getMemoryInfo(outInfo);
                        MEMORY= (int) ((outInfo.availMem*100/outInfo.totalMem));

                    }else {
                        ActivityManager am = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
                        ActivityManager.MemoryInfo outInfo = new ActivityManager.MemoryInfo();
                        am.getMemoryInfo(outInfo);
                        MEMORY = (int) ((outInfo.availMem*100/outInfo.totalMem));
                        break;
                    }
                }
            }
            private int doWork(){
                time+=1000;
                try {
                    Thread.sleep(1000);
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
                return time;
            }
        }).start();
    }
}
